package likou;


/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/07/14 16:15
 */
public class _98 {


    public static void main(String[] args) {
        Integer[] integers = {3, 1, 5, 0, 2, 4, 6, null, null, null, 3};
        TreeNode tree = TreeUtil.createTree(integers);
    }

    long last = Long.MIN_VALUE;
    boolean flag = true;
    public boolean isValidBST(TreeNode root) {
        if(root==null){
            return true;
        }
        if(root.left==null && root.right==null){
            int cur = root.val;
            if(cur<=last){
                flag = false;
                return flag;
            }
            last = cur;
            return true;
        }
        if(root.left!=null){
            flag = isValidBST(root.left);
            if(!flag){
                return flag;
            }
        }

        if(root.val<=last){
            flag = false;
            return flag;
        }
        last = root.val;
        if(root.right!=null){
            flag = isValidBST(root.right);
            if(flag == false){
                return flag;
            }
        }
        return true;
    }
}
